<?php

class ControllerModuleCategoryslidershow extends Controller {

    protected function index($setting) {
        static $module = 0;

        $this->document->addScript('catalog/view/javascript/jquery/jquery.jcarousel.min.js');
        $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/carousel.css');

        $this->language->load('module/categoryslidershow');

        $this->data['heading_title'] = $this->language->get('heading_title');

        $this->data['button_cart'] = $this->language->get('button_cart');

//		$this->load->model('catalog/product');
        $this->load->model('catalog/categoryslidershow');
        $this->load->model('catalog/category');

        $this->load->model('tool/image');

        $this->data['products'] = array();

        $data = array(
            'filter_category_id' => $setting['category_id'],
            'start' => 0,
            'limit' => 21
        );
        /*
          print "<pre>";
          print_r($setting);
          print "</pre>";
         */
        $category_info = $this->model_catalog_category->getCategory($setting['category_id']);
        if ($category_info['image']) {
            $category_info['image'] = $this->model_tool_image->resize($category_info['image'], 42, 42);
        } else {
            $category_info['image'] = false;
        }
        $this->data['category'] = $category_info;

        $results = $this->model_catalog_categoryslidershow->getProducts($data);
        //$this->model_catalog_product->getRProducts($data);

        foreach ($results as $result) {
            if ($result['image']) {
                $image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
            } else {
                $image = false;
            }

            if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
            } else {
                $price = false;
            }

            if ((float) $result['special']) {
                $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
            } else {
                $special = false;
            }

            if ($this->config->get('config_review_status')) {
                $rating = $result['rating'];
            } else {
                $rating = false;
            }

            $this->data['products'][] = array(
                'product_id' => $result['product_id'],
                'image' => $this->config->get('config_url') . "image/" . $result['image'],
                'thumb' => $image,
                'name' => $result['name'],
                'price' => $price,
                'special' => $special,
                'rating' => $rating,
                'reviews' => sprintf($this->language->get('text_reviews'), (int) $result['reviews']),
                'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
            );
        }

        $this->data['module'] = $module++;
        $this->data['limit'] = $setting['limit'];
        $this->data['scroll'] = 'true';


        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/categoryslidershow.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/categoryslidershow.tpl';
        } else {
            $this->template = 'default/template/module/categoryslidershow.tpl';
        }

        $this->render();
    }

}

?>